package model
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.geom.Point;
	
	public class User extends EventDispatcher
	{
		private var _id:Number;
		private var _ip:String;
		private var _username:String;
		private var _email:String;
		private var _location:Point;
		private var _registerTime:String;
		private var _birthDay:String;
		private var _gender:int;
		private var _nickName:String;
		private var _mark:String;
		private var _city:String;
		private var _adress:String;
		private var _latestLoginTime:String;
		private var _avatarUrl:String;
		
		private var _items:Vector.<LuckyItem>;
		public function User(user:Object)
		{
			super(null);
			id = user.id;
			ip = user.ip;
			username = user.username;
			email = user.email;
			location = new Point(Number(user.location.split(",")[0]),Number(user.location.split(",")[1]));
			registerTime = user.registerTime;
			birthDay = user.birthDay;
			gender = int(user.gender);
			mark = user.mark;
			city = user.city;
			adress = user.adress;
			latestLoginTime = user.latestLoginTime;
			avatarUrl = user.avatar_url;
			
			_items = new Vector.<LuckyItem>();
		}

		public function get id():Number
		{
			return _id;
		}

		public function set id(value:Number):void
		{
			_id = value;
		}
		
		public function get ip():String
		{
			return _ip;
		}

		public function set ip(value:String):void
		{
			_ip = value;
		}

		public function get username():String
		{
			return _username;
		}

		public function set username(value:String):void
		{
			_username = value;
		}

		public function get email():String
		{
			return _email;
		}

		public function set email(value:String):void
		{
			_email = value;
		}

		public function get location():Point
		{
			return _location;
		}

		public function set location(value:Point):void
		{
			_location = value;
		}

		public function get registerTime():String
		{
			return _registerTime;
		}

		public function set registerTime(value:String):void
		{
			_registerTime = value;
		}

		public function get birthDay():String
		{
			return _birthDay;
		}

		public function set birthDay(value:String):void
		{
			_birthDay = value;
		}

		public function get gender():int
		{
			return _gender;
		}

		public function set gender(value:int):void
		{
			_gender = value;
		}

		public function get nickName():String
		{
			return _nickName;
		}

		public function set nickName(value:String):void
		{
			_nickName = value;
		}

		public function get mark():String
		{
			return _mark;
		}

		public function set mark(value:String):void
		{
			_mark = value;
		}

		public function get city():String
		{
			return _city;
		}

		public function set city(value:String):void
		{
			_city = value;
		}

		public function get adress():String
		{
			return _adress;
		}

		public function set adress(value:String):void
		{
			_adress = value;
		}

		public function get latestLoginTime():String
		{
			return _latestLoginTime;
		}

		public function set latestLoginTime(value:String):void
		{
			_latestLoginTime = value;
		}

		public function get avatarUrl():String
		{
			return _avatarUrl;
		}

		public function set avatarUrl(value:String):void
		{
			_avatarUrl = value;
		}
		
		public function get items():Vector.<LuckyItem>
		{
			return _items;
		}

		public function addItem(item:LuckyItem):void
		{
			for each(var i:LuckyItem in _items)
			{
				if(i.id == item.id)
				{
					_items.splice(_items.indexOf(i),1);
					break;
				}
			}
			_items.push(item);
		}


	}
}